package org.chat.hhdchat;

import jakarta.annotation.PostConstruct;
import org.chat.hhdchat.config.NettyServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

@SpringBootApplication(exclude = {
        DataSourceAutoConfiguration.class,        // 禁用默认数据源自动配置
        MongoAutoConfiguration.class,             // 禁用默认 MongoDB 自动配置
        MongoDataAutoConfiguration.class,
})
@EnableMongoRepositories(basePackages = "org.chat.hhdchat.repository")
public class HhdChatApplication {

    private final NettyServer nettyServer;

    @Autowired
    public HhdChatApplication(NettyServer nettyServer) {
        this.nettyServer = nettyServer;
    }

    public static void main(String[] args) {
        SpringApplication.run(HhdChatApplication.class, args);
    }

    @PostConstruct
    public void init() {
        // 确保启动 Netty 服务器
//        nettyServer.start();
        new Thread(() -> nettyServer.start()).start(); // 异步启动
    }

}
